In the H.264 protocol, arithmetic coding is a common coding method for data compression in video processing, and its underlying rationale is as follows: processing the probability space in accordance with the current value of the binary data in the video coding circuit, acquiring the processed probability space for updating and renormalization, and generating the code stream according to the updated probability space. The generated code stream comprises coding output bytes, which are the final output from the encoder.
The probability space is usually indicated by the starting position (CodLow) and the length (CodRange) of the probability space. CodLow and CodRange are usually indicated in binary numbers. The values of CodRange and CodLow are updated in the H.264 protocol as follows:
The value of CodRange usually consists of nine bits, each being “0” or “1”, the most significant bit being the 8th bit, the second most significant bit being the 7th bit; the same rule applies to the remaining bits, with the least significant bit as 0th bit. If the value of a bit in the CodRange value to be updated is 1 and all the upper bits preceding it are 0's, mark this bit as the mth bit. Then remove all the upper bits preceding the mth bit, put the mth bit and all the succeeding bits in turn into the starting position of the most significant bit, and assign zero to all the vacant lower bits. The CodRange value thus obtained is the updated CodRange value. For example, the value of a CodRange is 0001xxxxx, to update it, remove “0” from the 8th, 7th, and 6th bits, and use the succeeding “1xxxxx” as the 8th-3rd bits of the updated CodRange, and fill “0” into the vacant 2th-0th bits. Hence, the CodRange value is updated: 1xxxxx000, which will be used for the next renormalization.
The value of CodLow usually consists of ten bits, each being “0” or “1”, the most significant bit being the 9th bit, the second most significant bit being the 8th bit; the same rule applies to the remaining bits, with the least significant bit as 0. The value of CodLow is updated according to the CodRange value and the CodLow value to be updated. Specifically, starting from the most significant bit of the CodRange value to be updated, if a certain bit is “1” and all the upper bits preceding it are 0's, all the significant bits preceding it are marked as n. If the upper n bits of CodLow to be updated are all 1's, i.e, its upper n bits all being “1 . . . 1”, remove these n bits from CodLow, move all the succeeding bits to the positions of the removed upper bits in turn, and fill “0” in all the vacant least significant bit positions. If not all the n upper bits of CodLow are 1's, remove the n bits in CodLow, fill “0” in the most significant bit position, move the succeeding bits in turn to the positions starting from the second most significant bit, and fill “0” in the vacant least significant bit positions. The CodLow value thus obtained is the updated CodLow value. The updated CodLow value will be used for next renormalization.
While CodRange and CodLow are being updated, coding output bytes are output simultaneously. When the 8-bit output characters of a coding output byte are all filled up, this coding output byte will be output. The 8-bit output characters of the coding output byte are arranged in descending order of priority. Detailed below is a description of the conditions for the acquisition of the 8-bit output characters of coding output bytes.
Coding output bytes are acquired with reference to the values of CodRange and CodLow. The output characters comprised in output bytes are determined by two adjacent bits in the CodLow value, which are arranged in descending order of priority. Specifically, the 9th bit and the 8th bit determine one output character; so do combinations of the 8th bit and the 7th bit, the 7th bit and the 6th bit, and the 6th bit and the 5th bit. The same rule applies for other output characters. The number of valid output characters determined by a CodRange value to be updated equals to the number of the upper bits removed from the CodRange value when CodRange is updated. For example, if the number of the upper bits removed from a CodRange value during its update is 3, the number of valid output characters determined by the CodLow value to be updated will also be 3, comprising the ones determined by the 9th bit and the 8th bit, the 8th bit and the 7th bit, and the 7th bit and the 6th bit.
The rationale for the determination of output characters by two adjacent bits in the CodLow value comprises:
If the two adjacent bits are 00, the output character is 0;
if the two adjacent bits are 01, the output character is in undetermined state;
if the two adjacent bits are 10, the output character is 1; and
if the two adjacent bits are 11, the output character is 1.
For two adjacent bits of a CodLow value to determine output characters, if either of the adjacent the 9th bit and the 8th bit is 0, each pair of two adjacent bits succeeding them determines the output characters, and it is necessary to set the value of the most significant bit of each pair succeeding the 9th bit and the 8th bit to “0”; if the 9th and 8th bits are both 11, it is unnecessary to change the values of each pair. For example, if the value of CodLow is 1010110001, the output character determined by the 9th and 8th bits is 1; one of the two bits is 0 (i.e, the 9th bit is 0), so when the 8th bit and the 7th bit (i.e 01) are to determine an output character, set the 8th bit to 0 which was originally 0; the output character determined by the original value (01) of the 8th bit and the 7th bit is in undetermined state; for the 7th bit and the 6th bit (i.e 10) to determine an output character, set the 7th bit to 0, it is 00 that determines the relevant output character, which is 0; for the 6th bit and the 5th bit (i.e 01) to determine an output character, set the 6th bit to 0 which was originally 0, the output character determined by the 6th bit and the 5th bit (original value being 01) is in undetermined state; for the 5th bit and the 4th bit (i.e 11) to determine an output character, set the 5th bit to 0, the output character determined by 01 is in undetermined state; the same rule applies for the other output characters.
After the output characters are acquired according to the values of CodRange and CodLow, judge them one by one; if an output character is in undetermined state, perform integrated counting on this character and continue to acquire the next output character; if an output character currently obtained is not in undetermined state, enter it into the current coding output byte; judge whether the value of the output character in undetermined state is 0, if yes, enter the output character currently obtained into the current coding output byte; if not, enter it into the current coding output byte, enter the number of the output characters in undetermined state and the output character opposite to the currently obtained output character into the current coding output byte.
To meet the conditions for renormalization and package outputting in the protocol, and implement renormalization and package outputting of arithmetic codes, the prior art employs the serial processing method for software implementation. This method requires multiple loops to complete one renormalization process, and will generate output characters and output related code streams during renormalization.
In the H.264 protocol, the value ranges of CodRange and CodLow are [2, 255] and [0, 1023] respectively. FIG. 1 details the prior art renormalization and packaging procedures, wherein the reference probability space [0, 1023] is used as an example. The method comprises:
In Step 101, judge if CodRange is less than 256, i.e, if CodRange is less than ¼ of the total length of the reference probability space; if yes, perform step 102; otherwise, end the procedure.
Judge if CodRange, indicated in a binary code, is less than 256, that is, judge if the most significant bit of the 9-bit CodRange is 0;
In Step 102, judge if CodLow is less than 256, i.e, if the current probability space is located in the lower half of the reference probability space; if yes, perform step 104; otherwise, perform step 103;
Judge if CodLow, indicated in a binary code, is less than 256, that is, judge if the most significant bit and the second most significant bit of the 10-bit CodLow are both 0's;
In Step 103, judge if CodLow is equal to or greater than 512, i.e, if the current probability space is located in the upper half of the reference probability space; if yes, perform step 106; otherwise, perform step 105;
In Step 104, generate one “0” as an output character, generate as many 1's as the count displayed on the counter (i.e, as many 1's as the count) for output characters, reset the counter and perform step 108;
In Step 105, deduct 256 from the CodLow value, i.e, move the position of the current probability space to the lower half by ¼ of the total length of the reference probability space, add 1 to the count of the counter, and perform step 108;
In Step 106-step 107, deduct 512 from the CodLow value, i.e, move the position of the current probability space to the lower half by ½ of the total length of the reference probability space, generate one “1” as an output character and as many 0's as the count displayed on the counter (i.e, as many 0's as the count) for output characters; afterwards, reset the counter and perform step 108; and
In Step 108, respectively multiply the CodLow value and the CodRange value by 2, i.e, double the length of the current probability space, and return to step 101.
In the foregoing procedure, step 101 to step 108 constitute a loop.
According to the procedure, the probability space is updated by updating the values of CodLow and CodRange; and output characters are acquired during renormalization and update of the probability space. However, when each loop comes to step 108, the length of the probability space is doubled; return to step 101 for judgment; the current renormalization procedure ends only when CodRange is equal to or greater than 256. If the minimum value of CodRange is 2 in step 101, seven loops are needed to complete the whole renormalization procedure, which will consume a considerable amount of unit time.
Evidently, the renormalization is inefficient, which in turn slows probability space updating and video processing, and reduces the efficiency of arithmetic coding. Furthermore, CodLow and CodRange updating, and output character generation are mixed, making it difficult to increase the processing efficiency.
Therefore, a heretofore unaddressed need exists in the art to address the aforementioned deficiencies and in adequacies.